<!--
<!DOCTYPE html>
<html>
<head>
<head />
<div th:include="base-libs :: base-libs" />
&lt;!&ndash; <div th:include="common/fwb-modal :: fwb-modal" />
<div th:include="common/xypl-modal :: xypl-modal" />
<div th:include="common/zj-modal :: zj-modal" />
<div th:include="common/bgfwbpl-modal :: bgfwbpl-modal" />
<div th:include="common/common-export :: common-export" /> &ndash;&gt;


&lt;!&ndash; <link th:href="${quickJs}+'scripts/jquery/plug-ins/bootstrap-table/bootstrap-table.min.css'" rel="stylesheet"/>
<script th:src="${quickJs}+'scripts/jquery/plug-ins/bootstrap-table/bootstrap-table.min.js'"></script>
<link rel="stylesheet" th:href="${appName} + 'css/bootstrap-select.min.css'"/>	
<script th:src="${appName} + 'js/bootstrap-select.min.js'"></script>		 		 
<script th:src="${quickJs}+'scripts/jquery/plug-ins/bootstrap-table/bootstrap-table-zh-CN.min.js'"></script> &ndash;&gt;
<script th:src="'/service/js/jtqy.js'"></script>

<title>正式签约</title>
<style type="text/css">
body {
	padding: 0px 10px;
}

.table>tbody>tr>td {
	vertical-align: middle !important;
	text-align: center !important;
}

.btnTable {
background-color: white;
color: black;
}

.form-table select {
	width: 100%;
}
</style>
</head>
<script th:inline="javascript">
	/**读取request中的初始化数据*/
var data = [[${data}]];
</script>
<script type="text/javascript">
	$(function() {
 	btnTableSwitch();
 	//initDate();
 	//initView();
 	//queryForm();
});

/**
*
*/
function queryForm() {
	$("#dgForm").datagrid({"url":  contextRoot+"jtqy/queryPage.service" });
}
function queryHandler() {
	$("#dgForm").datagrid("load");
}
function colseOpenBackHandler(){
	var value = StoreCache.removeCache("JTQY_OPT_SUCCESS");
	if(!StringUtils.isEmpty(value)){
		queryReload();
	}
}

function btnTableSwitch(){
	$(".btnTable").each(function(){
		var id = $(this).attr("option");
		var height = $(this).attr("optionData");
		$(this).bind("click",function(){
			$(".activeQuery").remove();
			$("#formTable tbody").append($("#" + id ).html());
			setHeight(height);
		});
	});
	$(".btnTable").eq(0).trigger("click");
}

function setHeight(num){
    var c=$("body");
    var p=c.layout('panel','north');  //get the north panel
    var oldHeight=p.panel('panel').outerHeight(); //获得north panel 的原高度
    p.panel('resize',{height:num}); //设置north panel 新高度
    var newHeight=p.panel('panel').outerHeight();
    c.layout('resize',{height:c.height()+newHeight-oldHeight});  //重新设置整个布局的高度
}


function queryReload(){
	$("#dgForm").datagrid("reload");
}

function initDate(){
	$(".form-control").CacheForSelect();
	fwbDataSelectInit();
	var endTimeObj = {
			elem: '#QYJSSJ',
		  	choose: function(datas){
		  		startTimeObj.max = datas;
		    }
	};
	laydate(endTimeObj);
	//生效日期
	var startTimeObj = {
		 elem: '#QYKSSJ',
	  	 choose: function(datas){
	  		endTimeObj.min = datas;
	  	 }
	};
	laydate(startTimeObj);
}

function fwbDataSelectInit(){
	for(var i = 0; i < data.tdAry.length ; i ++){
		var item = data.tdAry[i];
		var option = $("<option>").val(item["TDID"]).html(item["TDMC"]);
		$("#YLTDID").append(option);
	}
}

function initView()
{
	$("#dgForm").datagrid({
		idField : "QYXXID",
		striped : true,
		fit:true,
		fitColumns:true,
		columns : [[
			{
			    field: "checkStatus",
				checkbox: true
			}, 
			{
				field : "XM",
				title : "姓名"
				,width:20
			},
			{
				field : "ZJHM",
				title : "证件号码"
				,width:20
			},
			{
				field : "SJHM",
				title : "手机号码"
				,width:20
			},
			{
				field : "JTZZ",
				title : "家庭住址"
				,width:20
			},
			{
				field : "QYSJ",
				title : "签约时间"
				,width:20
			},
			{
				field : "RQFLMC",
				title : "人群分类"
				,width:20
			},
			{
				field : "TDMC",
				title : "签约团队"
				,width:20
			},
			{
				field : "FWBMC",
				title : "签约服务包"
				,width:20
			},
			{
				field : "QYLX",
				title : "签约状态",
				width:20,
				formatter : function(value, row, index) {
					return getQylx(value);
				}
			},
			{
				field : "cz",
				title : "操作",
				width:20,
				formatter : function(value, row, index){
					row = JSON.stringify(row).replace(/"/g, '&quot;') 
					return '<a class="detail tableToolBarBtn" href="javascript:;" onClick="operateFormatter(' + row + ');" title="详细">详细</a>';
				}
			}
		]]
		,pagination : true
		,contentType: "application/x-www-form-urlencoded; charset=UTF-8"
		,sidePagination: "server"
			,pageNumber : 1
			,pageSize : 10
			,pageList: [10, 20, 50, 100, 200]
		,method : "post"
		//,url: contextRoot+"jtqy/"
		,onBeforeLoad: function(params){
			params["ZJHM"] = $("#ZJHM").val();
			params["XM"] = $("#XM").val();
			params["RQFLID"] = $("#RQFL").val();
			params["FWBID"] = $("#FWBID").val();
			params["YLJGID"] = parent.userInfo.PTJGID;
			params["YLTDID"] = $("#YLTDID").val();
			params["QYKSSJ"]=$("#QYKSSJ").val();
			params["QYJSSJ"]=$("#QYJSSJ").val();
			return params;
		}
	
	});
	
	//解约
	$("#btnJy").on("click", function(){
		var selection = getCheckedRows();
		if(selection.length>0){
	    	var invalidArray = new Array();
		    $.each(selection, function(index, item)
			{ 
			   if(!StringUtils.isEmpty(item["QYLX"]) && item["QYLX"]!="01"){
				   invalidArray.push(item);
			   }
			});
		    if(invalidArray.length>0){
		    	$.QuickAlert.alertFail({content : "已经失效的数据不能做解约操作！"});
		    	return ;
		    }else{
				parent.layer.confirm('您确定要解约这' + selection.length + '个人吗？' , {icon: 3, title:'提示'}, function(index){
					  parent.layer.close(index);
					  parent.layer.prompt({title: '请填写解约原因', formType: 2}, function(text, index){
					    if(StringUtils.isEmpty(text)){
					    	parent.layer.msg('请填写解约原因！');
					    	return;
					    }
					    qyxxJyFun(text);
					    parent.layer.close(index);
					  });
					});
		    }
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		}
	});
	//解约更新
	function qyxxJyFun(jyyy){
		var selection = getCheckedRows();
		var qyxxidArray = new Array();
		 $.each(selection, function(index, item)
		{ 
		   qyxxidArray.push(item["QYXXID"]);
		});
		var param = {
			QYXXIDS:qyxxidArray.join(","),
			ZTMS:jyyy
		};
		var jyurl = $.QuickUrlUtils.getProjectName()+"/jtqy/jyfw.service"
		$.QuickRemote.AjaxJson(jyurl,function(result){
			if (result["state"]) {
			   $.QuickAlert.alertNormal("解约成功！",{callback: function(){
				   queryReload();
				}});
			} else {
				$.QuickAlert.alertFail({
					content : info["faultInfo"]
				});
			}
		},param);
	}

	//续约点击按钮事件
	$("#btnXy").on("click", function(){
		alert("反人类设计，需要重新设计！");
		return ;
		var selection = getCheckedRows();
		if(selection.length>0){
			var qysjArray = new Array();
	    	var count = 0;
	    	var xyInvalidArr = new Array();
		    $.each(selection, function(index, item)
			{ 
			   qysjArray.push(item["QYSJ"]);
			   if(!StringUtils.isEmpty(item["QYLX"]) && item["QYLX"]=="02"){
				   xyInvalidArr.push(item);
			   }
			});
		    if(xyInvalidArr.length>0){
		    	$.QuickAlert.alertFail({content : "已经解约的数据不可以做续约操作！"});
		    	return ;
		    }
		    
	    	for (var i = 0; i < qysjArray.length;i++) {  
	    	    for (var j = i; j < qysjArray.length; j++) {  
	    	        if (qysjArray[i] == qysjArray[j]) {  
	    	        	count++;  
	    	        }  
	    	    }  
	    	}
	    	if(count==selection.length){
				var notice = "你已经选择了"+selection.length+"记录";
				$("#xypl-Modal").find(".notice").html(notice);
				$("#xypl-Modal").find("#QYSJ").val(selection[0]["QYSJ"])
				$("#xypl-Modal").find("#JSSJ").val(selection[0]["JSSJ"])
				$("#xypl-Modal").find("#TDMC").val(selection[0]["TDMC"])
				$("#xypl-Modal").find("#FWBMC").val(selection[0]["FWBMC"])
				
				var days = dateDiff(selection[0]["QYSJ"],selection[0]["JSSJ"]);
                var startDate = getSepDate(selection[0]["JSSJ"],1);//开始时间
                var endDate = getSepDate(startDate,days);//结束时间
				$("#xypl-Modal").find("#XYSXSJ").val(startDate);
				$("#xypl-Modal").find("#XYJSSJ").val(endDate);
				$("#xypl-Modal").modal("show");
	    	}else{
		    	$.QuickAlert.alertFail({content : "你选择的数据，签约时间不同，不能一起操作！"});
	    	}
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		}
	});
	
	$("#xypl-Modal").on("show.bs.modal", function () {
		loadTdData();
		loadDataXyFwb();
	});

	/**确认选择服务项*/
	$("#xypl-Modal").on("click", ".enter", function(){
		    $(".back").trigger("click");
		   	var nowdate = new Date();
		   	var currentdate =nowdate.format('yyyy-MM-dd');
	    	var qyxxidArray = new Array();
		    $.each(selection, function(index, item)
			{ 
			   console.log("fwbDataArray-"+JSON.stringify(item));
			   qyxxidArray.push(item["QYXXID"]);
			});
		    var xytdid = $("#method").val("XY");
			alert("ids-"+$("#XYFWBID").val());

			var param = {
				QYXXIDS:qyxxidArray.join(","),
				method:"XY",
			    TDID:$("#XYTDID").val(),
			    FWBID:$("#XYFWBID").val(),
		        SXSJ:$("#XYSXSJ").val(),		    
		        JSSJ:$("#XYJSSJ").val(),
		        FWBID:$("#XYFWBID").val(),
		        YLTDID:$("#XYTDID").val(),
		        QYSJ:$("#XYSXSJ").val()
			};
			
			var xyurl = $.QuickUrlUtils.getProjectName()+"/jtqy/save.service"
			$.QuickRemote.AjaxJson(xyurl,function(result){
				if (result["state"]) {
				   $.QuickAlert.alertNormal("续约成功！",{callback: function(){
						$.QuickUrlUtils.redirectUrl("index.html");
					}});
				} else {
					$.QuickAlert.alertFail({
						content : info["faultInfo"]
					});
				}
			},param);
	});
	
	

	//变更服务包
	$("#btnBgfwb").on("click", function(){
		var selection = getCheckedRows();
		//alert(JSON.stringify(selection));
		if(selection.length>0){
			var tdid = selection[0].TDID;
			var fwbid = selection[0].FWBID;
			var count = 0; 
			var qyids = [];
		    $.each(selection, function(index, item)
			{ 
		       qyids.push(item["QYXXID"]);
			   if(tdid != item["TDID"] || item["QYLX"] != "01" || fwbid != item["FWBID"]){
				   return ;
			   }
			   count++;
			});
	    	if(count==selection.length){
	    		
	    		parent.layer.open({
					type : 2,
					title : "变更服务包操作",
					shadeClose : false,
					shade : 0.8,
					area : [ "600px", "350px" ],
					content: contextRoot + 'model/bgfwbModel.html?RS=' +  count + '&QYXXIDS=' + qyids.toString() + '&FWBIDS=' 
							+ fwbid + "&YLJGID=" + parent.userInfo.PTJGID,//iframe的url
					end: colseOpenBackHandler
					}); 
	    	}else{
		    	$.QuickAlert.alertFail({content : "您选择的数据，签约团队，服务包不一致，或状态不是正常签约状态，不能一起操作！"});
	    	}
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		}
	});
	

	//转介
	//转介信息确认
	$("#btnZj").on("click", function(){
		var selection = getCheckedRows();
		if(selection.length>0){
	    	var TDID = selection[0].TDID;
			var qyids = [];
			var fwbids = [];
	    	var count = 0;
		    $.each(selection, function(index, item)
			{ 
		    	qyids.push(item.QYXXID);
		    	fwbids.push(item.FWBID);
		    	if(item.TDID==TDID && item.QYLX == '01'){ //通过团队id，如果团队名称一样怎么办？
		    		count ++ ;
		    	}
			});
	    	if(count==selection.length){
				parent.layer.open({
					type : 2,
					title : "转介申请",
					shadeClose : false,
					shade : 0.8,
					area : [ "350px", "335px" ],
					content: contextRoot + 'model/zjModel.html?TDZT=1&TDID=' + TDID + '&RS=' +  count + '&QYXXIDS=' + qyids.toString() 
							+ '&FWBIDS=' + fwbids.join(";") + "&YLJGID=" + parent.userInfo.PTJGID,//iframe的url
					end: colseOpenBackHandler
					}); 
	    	}else{
		    	$.QuickAlert.alertFail({content : "您选中的居民，签约团队不一致或签约状态不符合，无法一起转介。请勾选签约团队相同的居民进行批量转介！"});
	    	}
		}else{
	    	$.QuickAlert.alertFail({content : "请至少选择一条记录！"});
		} 
	});
	/**导出服务包*/
	$("#btnExport").on("click", function(){
		
		var selection = getCheckedRows();
		if(selection.length > 0){
	    	var qyxxidArray = new Array();
		    $.each(selection, function(index, item)
			{ 
			   qyxxidArray.push(item["QYXXID"]);
			});
			$("#QYXXIDS").val(qyxxidArray.join(","));
			/**导出必须用submit方法提交，不能用 封装的ajaxsubmit*/
			$("#exportForm").submit();
		}else{
			$.QuickAlert.alertFail({
				content : "请选择要导出的签约记录！"
			});
		}
	});
	/** 获取已选中的记录  */
	function getCheckedRows(){
		var selection = $("#dgForm").datagrid("getChecked");
		return selection;
	}
}

/**获取签约状态*/
function getQylx(qylx) {
	if (qylx == "01") {
		qylx = "签约";
	} else if (qylx == "02") {
		qylx = "转介中"
	} else if (qylx == "03") {
		qylx = "已解约";
	}
	else if (qylx == "04") {
		qylx = "已到期 ";
	}
	else if (qylx == "00") {
		qylx = "预签约 ";
	}

	return qylx;
}

/**操作格式化*/
function operateFormatter(value) {
	console.log(value);
	StoreCache.setCache("JTQYINFO", value);
	location = "detail.html?JMXXID=" + value.JMXXID;
}
</script>
<body class="easyui-layout" fit="true" border="false">
	<div region="north"
		style="border: none; overflow: hidden; background-color: #f9f9f9;">
		<div style="width: 100%; margin-left: 30px">
			<h3
				style="line-height: 41px; margin: 0px; font-size: 18px;font-weight: bold;">签约查询</h3>
		</div>
		<div style="width: 100%; margin-left: 30px">
			<button id="btnQuery" class="btn btn-info btnTable" type="button" option="allToolBar" optionData="151" 
				id="btnQueryFwb" >全部</button>
			<button id="btnQuery" class="btn btn-info btnTable" type="button" option="ydqToolBar" optionData="151" 
				id="btnQueryFwb" >已到期</button>
			<button id="btnQuery" class="btn btn-info btnTable" type="button" option="yjyToolBar" optionData="192" 
				id="btnQueryFwb" >已解约</button>
			<button id="btnQuery" class="btn btn-info btnTable" type="button" option="yzjToolBar" optionData="192" 
				id="btnQueryFwb" >已转介</button>
		</div>
		<form id="exportForm" action="export.service" enctype="multipart/form-data">
			<input name="QYXXIDS" id="QYXXIDS" style="display: none;">
		</form>

		<table class="form-table" id="formTable" style="margin:0;padding:0;">
			<tr>
				<td class="td-text">姓名：</td>
				<td class="td-content"><input id="XM" name="XM"
					class="form-control dataField" type="text" style="width: 100%;">
				</td>
				<td class="td-text">证件号码：</td>
				<td class="td-content">
					<div style="display: inline;">
						<input id="ZJHM" name="ZJHM" class="form-control dataField"
							style="width: 100%;" />
					</div>
				</td>
				<td class="td-text">签约团队：</td>
				<td class="td-content"><select id="YLTDID" name="YLTDID"
					class="form-control">
				</select></td>
				<td class="td-text" style="width:150px">
					<button id="btnQuery" class="btn btn-info" type="button"
						id="btnQueryFwb" onclick="queryHandler()">查询</button>
					<button id="btnQuery" class="btn btn-info" type="button"
						id="btnQueryFwb" onclick="queryHandler()">导出</button>
				</td>
			</tr>
		</table>
	</div>
	<div region="center" style="height:150px;">
		<table id="dgForm">
		</table>

	</div>

</body>
<script type="text/html" id="tableToolBar">
<a class="detail tableToolBarBtn" href="javascript:void(0)" title="详细">详细</a>
</script>

<script type="text/html" id="zjToolBar">
<textarea class="layui-layer-input"></textarea>
<select class="layui-layer-select"></select>
</script>
<script type="text/html" id="allToolBar">
<tr class="activeQuery">
<td class="td-text">签约时间：</td>
<td class="td-content">
	 <input id="QYKSSJ" name="QYKSSJ" style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text">至：</td>
<td class="td-content">
	<input id="QYJSSJ" name="QYJSSJ" style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text">签约状态：</td>
<td class="td-content">
	<select id="FWBID" name="FWBID" class="form-control">
		<option value="">请选择</option>
		<option value="00">预签约</option>
		<option value="01">已签约</option>
		<option value="03">已解约</option>
		<option value="04">已到期</option>
		<option value="05">已续签</option>
		<option value="09">已转介</option>
	</select>
</td>
<td class="td-text">
</td>
</tr>
</script>
<script type="text/html" id="ydqToolBar">
<tr class="activeQuery">
<td class="td-text">签约时间：</td>
<td class="td-content"><input id="QYKSSJ" name="QYKSSJ"
	style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text">至：</td>
<td class="td-content"><input id="QYJSSJ" name="QYJSSJ"
	style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text">到期时间：</td>
<td class="td-content">
	<input id="DQSJ" name="DQSJ" style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text"></td>
</tr>
</script>
<script type="text/html" id="yjyToolBar">
<tr class="activeQuery">
<td class="td-text">签约时间：</td>
<td class="td-content">
	 <input id="QYKSSJ" name="QYKSSJ" style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text">至：</td>
<td class="td-content">
	<input id="QYJSSJ" name="QYJSSJ" style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text"></td>
<td class="td-content">
</td>
<td class="td-text">
</td>
</tr>
<tr class="activeQuery">
<td class="td-text">解约时间：</td>
<td class="td-content"><input id="JYKSSJ" name="JYKSSJ"
	style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text">至：</td>
<td class="td-content"><input id="JYJSSJ" name="JYJSSJ"
	style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text"></td>
<td class="td-content"></td>
<td class="td-text"></td>
</tr>
</script>
<script type="text/html" id="yzjToolBar">
<tr class="activeQuery">
<td class="td-text">签约时间：</td>
<td class="td-content">
	 <input id="QYKSSJ" name="QYKSSJ" style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text">至：</td>
<td class="td-content">
	<input id="QYJSSJ" name="QYJSSJ" style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text"></td>
<td class="td-content">
</td>
<td class="td-text">
</td>
</tr>
<tr class="activeQuery">
<td class="td-text">转介时间：</td>
<td class="td-content"><input id="ZJKSSJ" name="ZJKSSJ"
	style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text">至：</td>
<td class="td-content"><input id="ZJJSSJ" name="ZJJSSJ"
	style="height:30px;" class="input-text laydate-icon dataField" />
</td>
<td class="td-text"></td>
<td class="td-content"></td>
<td class="td-text"></td>
</tr>
</script>
</html>
-->
